#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;
const int L = 2e6 + 10;
const int mod = 1e9 + 7;

int fa[L],id[20][N],n,m,tot,lg[N],pw[50];

int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
bool merge(int x,int y) { x = gf(x); y = gf(y); if(x == y) return 0; fa[x] = y; return 1; }
int getid(int x) { return x % n == 0 ? n : x % n; }

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in; for(int i = 2;i <= n;i++) lg[i] = lg[i >> 1] + 1;
	for(int i = (pw[0] = 1);i <= lg[n];i++) pw[i] = pw[i - 1] << 1;
	for(int i = 0;i <= lg[n];i++)
		for(int j = 1;j <= n;j++) id[i][j] = ++tot;
	for(int i = 1;i <= tot;i++) fa[i] = i;
	for(int i = 1;i <= m;i++) {
		int l1 = in,r1 = in,l2 = in,r2 = in; int len = r1 - l1 + 1;
		for(int k = lg[n];k >= 0;k--)
			if(len >> k & 1) {
				merge(id[k][l1],id[k][l2]); l1 += pw[k]; l2 += pw[k];
			}
	}
	for(int k = lg[n];k;k--)
		for(int i = 1;i + pw[k] - 1 <= n;i++) {
			int j = getid(gf(id[k][i]));
			merge(id[k - 1][i],id[k - 1][j]); merge(id[k - 1][i + pw[k - 1]],id[k - 1][j + pw[k - 1]]);
		}
	ll ans = 1; bool fl = 0;
	for(int i = 1;i <= n;i++) if(gf(i) == i) ans *= fl == 0 ? 9 : 10,ans %= mod,fl = 1;
	printf("%lld\n",ans);
	return 0;
}
